package com.artlongs.webapp.service.reactor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import reactor.core.Reactor;
import reactor.event.Event;
import reactor.function.Consumer;

import static reactor.event.selector.Selectors.$;

@Service
public class TestService {

    @Autowired
    private Reactor reactor;

    public void fireEvent(String s) {
        //通告一个[event]事件
        reactor.notify("event", Event.wrap(s));

        //监听一个名为event的事件，消费者为Consumer
        reactor.on($("event"), new Consumer<Event<String>>() {
            @Override
            public void accept(Event<String> t) {
                System.out.println("This is sample code : " + t.getData());
            }
        });
    }

}